﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;

namespace HYRElectric.Equipment
{
	internal class RoomSelectionFilter : ISelectionFilter
	{
		public RoomSelectionFilter(bool bPickElemInLinkDoc)
		{
			this.m_bPickElemInLinkDoc = bPickElemInLinkDoc;
		}

		public bool AllowElement(Element elem)
		{
			if (!this.m_bPickElemInLinkDoc)
			{
				return elem is Room;
			}
			this.m_currentInstance = (elem as RevitLinkInstance);
			return this.m_currentInstance != null;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			if (!this.m_bPickElemInLinkDoc)
			{
				throw new NotImplementedException();
			}
			if (this.m_currentInstance == null)
			{
				return false;
			}
			Element element = this.m_currentInstance.GetLinkDocument().GetElement(reference.LinkedElementId);
			return element != null && element is Room;
		}

		private bool m_bPickElemInLinkDoc;

		private RevitLinkInstance m_currentInstance;
	}
}
